<template>
  <div class="plr-box">
    <!-- right -->
    <div class="plr-top">
      <!-- 头部 -->
      <div class="pr-t">
        <span>喜欢这首歌</span>
      </div>
      <!-- 喜欢这个歌单的人 -->
      <div class="pr-img">
        <img
          :src="userimg.avatarUrl"
          alt=""
          v-for="userimg in subscribers"
          :key="userimg.userId"
          @click="gouserhome(userimg.userId)"
        />
      </div>
    </div>
    <div>
      <div class="r-tt">
        <span>热门歌单</span>
      </div>
      <div
        class="r-but"
        v-for="play in playlists"
        :key="play.id"
        @click="goplaylists(play.id)"
      >
        <a><img :src="play.coverImgUrl" alt="" /></a>
        <div class="r-btn-r">
          <p class="btn-name">
            <a>{{ play.name }}</a>
          </p>
          <p class="btn">
            <span>by</span>
            <a>{{ play.creator.nickname }}</a>
          </p>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "RightPlayList",
  data() {
    return {
      id: this.$route.query.id,
      // 推荐歌单
      playlists: [],
      // 收藏者
      subscribers: [],
    };
  },
  mounted() {
    this.getRrelatedPlayList();
    this.getSubscribers();
  },
  methods: {
    // 获取热门歌单
    async getRrelatedPlayList() {
      const result = await this.$API.reqRrelatedPlayList(this.id);
      // console.log(result)
      if (result.code == 200) {
        this.playlists = result.playlists || [];
      }
    },
    // 跳转到歌单
    goplaylists(id) {
      this.$router.push(`/playlists?id=${id}`);
    },
    // 获取歌单收藏者 reqSubscribers
    async getSubscribers() {
      /*  id : 歌单 id
      可选参数 : limit: 取出评论数量 , 默认为 20
      offset: 偏移数量 , 用于分页 , 如 :( 评论页数 -1)*20, 其中 20 为 limit 的值
      接口地址 : /playlist/subscribers
      调用例子 : /playlist/subscribers?id=544215255&limit=30 
      
      */
      const params = {
        id: this.id,
        limit: 8,
      };
      const result = await this.$API.reqSubscribers(params);
      // console.log(result)
      if (result.code == 200) {
        this.subscribers = result.subscribers;
      } else {
        alert("获取收藏者失败");
      }
    },
    gouserhome(id) {
      // console.log(id)
      this.$router.push(`/userhome?id=${id}`);
    },
  },
};
</script>

<style lang="less" scoped>
.plr-box {
  width: 200px;
  margin: 0 auto;
  .plr-top {
    .pr-t {
      border-bottom: 1px solid rgb(204, 204, 204);
      height: 24px;
      span {
        font-weight: bold;
        font-size: 12px;
        line-height: 24px;
      }
    }
    .pr-img {
      // height: ;
      margin-right: 10px;
      display: flex;
      justify-content: space-between;
      flex-wrap: wrap;
      img {
        margin-top: 10px;
        height: 40px;
        width: 40px;
      }
    }
  }

  .r-tt {
    padding-top: 10px;
    width: 100%;
    height: 30px;
    border-bottom: rgb(204, 204, 204) 1px solid;
    span {
      font-size: 14px;
      font-weight: bold;
    }
  }
  // 推荐歌单
  .r-but {
    margin-top: 10px;
    display: flex;
    img {
      height: 50px;
      width: 50px;
    }
    .r-btn-r {
      margin-left: 10px;
      display: flex;
      flex-direction: column;
      .btn-name {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        word-wrap: normal;
        width: 140px;
        a {
          color: #000;
          white-space: nowrap;
          word-wrap: normal;
        }
      }
      .btn {
        margin-top: 5px;
        display: flex;
        span {
          color: #999;
          font-size: 12px;
        }
        a {
          margin-left: 5px;
          width: 106px;
          font-size: 13px;
          color: #666;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
          word-wrap: normal;
        }
      }
    }
  }
}
</style>
